package com.xbh.dms.service.impl;

import com.jfinal.aop.Inject;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.redis.Redis;
import com.xbh.common.model.User;
import com.xbh.dms.service.LoginSrv;

/**
 * @LoginSrvImpl: 登录业务层实现类
 * @author: ZBoHang
 * @time: 2021/8/5 11:05
 */
public class LoginSrvImpl implements LoginSrv {

    @Override
    public String checkLogin(String userName, String userPass) {
        Record record = Db.findFirst("SELECT user_name,user_pass FROM tbl_user WHERE user_name =?", userName);
        if (record != null) {
            if (record.get("user_pass").equals(userPass)) {
                String token = StrKit.getRandomUUID();
                Redis.use("tokenCache").setex(token, 7200, System.currentTimeMillis() + 1000 * 60 * 60 * 24);
                return token;
            }
        }
        return null;
    }
}
